<template>
    <div class="applygod" v-if="showindex>=0">
        <div class="applycon" v-if="showindex===0">
            <h4>个人简介</h4>
            <textarea v-model="intro" class="txtcon" placeholder="10-100字，请简述自己的定位和价值，简介越详细申请成功概率越高。"></textarea>
            <a href="javascript:;" @click="appgodfn">确定申请</a>
        </div>
        <div class="applying" v-else>
            <msg :title="title" :description="description" :icon="icon"></msg>
        </div>
    </div>
</template>

<script>
    import {applayGodR, godApplyStatusR} from '../../service/god';
    import {getMytoken, getLogintoken} from '../../service/common';
    import {Msg} from 'vux';
    export default {
        components: {
            Msg
        },
        data() {
            return {
                title: '申请已成功提交',
                icon: 'waiting',
                description: '两到三个工作日给出审核结果',
                intro: '',
                showindex: -1
            };
        },
        created() {
            this.checkgodstatus();
        },
        computed: {},
        methods: {
            async checkgodstatus(){
                const {token} =await getMytoken();
                if(!token) {
                    this.$vux.toast.text('没拿到用户信息');
                    return;
                }
                const {data}=await godApplyStatusR(token);
                if(data && data.code === 0) {
                    this.showindex = 0;
                }
                else {
                    this.showindex = 1;
                    this.title = data.msg;
                    switch (data.code) {
                        case 17110903:
                            this.icon = 'success';
                            break;
                        case 17092827:
                            this.icon = 'warn';
                            break;
                        case 17070301:
                            this.icon = 'waiting';
                            break;
                    }
                }
            },
            async appgodfn(){
                const {token} =await
                getMytoken();
                const {intro}=this;
                if(!token) {
                    this.$vux.toast.text('没拿到用户信息');
                    return;
                }
                if(this.intro.length < 10) {
                    this.$vux.toast.text('请输入足够多的内容');
                    return;
                }
                const {data}=await
                applayGodR({token, intro});
                if(data && data.code === 0) {
                    this.showindex = 1;
                    this.icon = 'success';
                    this.title = '申请已成功提交';
                    this.$vux.toast.show({
                        text: '提交成功请等待'
                    })
                }
                else {
                    this.$vux.toast.text(data.msg)
                }
            }
        }
    }
</script>
<style scoped lang="less" rel="stylesheet/less">
    @import "../app";

    .applygod {
        background: #fff;
        height: 100%;
    }

    .applycon {
        background: #fff;
        padding-bottom: 40px;
        h4 {
            height: 100px;
            line-height: 100px;
            display: block;
            box-sizing: border-box;
            font-size: @fz30;
            text-indent: 30px;
        }
        .txtcon {
            width: 700px;
            height: 260px;
            margin: 0 auto;
            box-sizing: border-box;
            display: block;
            padding: 30px;
            border: 1px solid #ccc;
            border-radius: 8px;
            font-size: @fz30;
            margin-bottom: 30px;
        }
        a {
            background: @colororange;
            .setnormalcss(80px);
            font-size: @fz36;
            width: 700px;
            margin: 0 auto;
            display: block;
            color: #fff;
            border-radius: 4px;
        }
    }
</style>